/*******************************************************************************
 * Copyright (c) 2009-2011 ETCORE Labs. All rights reserved. 
 * 
 * This software is the confidential and proprietary information of ETCORE Labs.
 * You shall not disclose such confidential information and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with ETCORE Labs. 
 * 
 * Support can be obtained from support forums at:  http://www.etcore.com/
 * /
 *******************************************************************************/
package etcore.webapp.grouptalk.common.service;

import java.util.List;

import org.hibernate.Session;

import etcore.webapp.grouptalk.common.dao.HibernateSessionFactory;
import etcore.webapp.grouptalk.common.dao.MailDAO;
import etcore.webapp.grouptalk.common.object.Mail;

/**
 * MailService implements queries and transactions on Mail
 * 
 * @author ETCORE GroupTalk Developers
 * 
 */
public class MailService extends BaseService {

	public Mail findById(java.lang.Integer id) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MailDAO dao = new MailDAO();
			Mail result = dao.findById(id);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public Mail findByNameAndTime(String name, String time) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MailDAO dao = new MailDAO();
			Mail result = dao.findByNameAndTime(name, time);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeByProperty(String propertyName, Object value) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MailDAO dao = new MailDAO();
			long result = dao.findSizeByProperty(propertyName, value);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeBy2Properties(String propertyName, Object value,
			String propertyName2, Object value2) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MailDAO dao = new MailDAO();
			long result = dao.findSizeBy2Properties(propertyName, value,
					propertyName2, value2);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<Mail> findByProperty(String propertyName, Object value,
			int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MailDAO dao = new MailDAO();
			List<Mail> result = dao.findByProperty(propertyName, value, begin,
					length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<Mail> findBy2Properties(String propertyName, Object value,
			String propertyName2, Object value2, int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MailDAO dao = new MailDAO();
			List<Mail> result = dao.findBy2Properties(propertyName, value,
					propertyName2, value2, begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long searchSizeByProperty(String propertyName, String value) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MailDAO dao = new MailDAO();
			long result = dao.searchSizeByProperty(propertyName, value);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<Mail> searchByProperty(String propertyName, String value,
			int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MailDAO dao = new MailDAO();
			List<Mail> result = dao.searchByProperty(propertyName, value,
					begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findAllSize() {
		Session session = HibernateSessionFactory.getSession();
		try {
			MailDAO dao = new MailDAO();
			long result = dao.findAllSize();

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<Mail> findAll(int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MailDAO dao = new MailDAO();
			List<Mail> result = dao.findAll(begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<Mail> findAll() {
		Session session = HibernateSessionFactory.getSession();
		try {
			MailDAO dao = new MailDAO();
			List<Mail> result = dao.findAll();

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

}